﻿@model IMall.Web.Models.ViewModels.OrderModel
@{
    ViewBag.Title = "订单信息页面";
}
<div class="row clearfix">
    <ul class="breadcrumb" style="margin:0;background-color:white">
        <li>
            <a href="~/Home">首页</a>
        </li>
        <li class="active">
            订单信息
        </li>
    </ul>
</div>
<div class="alert @Model.StateCss" role="alert">
    当前订单状态： <strong>@Model.StateText</strong>
    @if (Model.State == 1)
    {
        <button class="btn btn-success" onclick="pay()">立即支付</button>
    }
    else if (Model.State == 3)
    {
        <button class="btn btn-success" onclick="complete()">确认收货</button>
    }
</div>
<div class="row clearfix" style="margin-top:20px;">
    <div class="col-md-12 column">
        <div class="tabbable" id="tabs">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="#panel" data-toggle="tab">订单信息</a>
                </li>
            </ul>
            <div class="tab-content" style="border:1px solid #EFEFEF">
                <div class="tab-pane active" id="panel" style="padding:10px;">
                    <p><strong>收货地址：</strong> @Model.Adress</p>
                    <p><strong>运送方式：</strong> 爱商城派送</p>
                    <hr />
                    <p><strong>卖家信息：</strong> 爱商城自营</p>
                    <hr />
                    <div class="row">
                        <div class="col-sm-6">
                            <strong>订单号：</strong> @Model.Id
                        </div>
                        <div class="col-sm-6">
                            <strong>创建时间：</strong> @Model.CreatedTime
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                            <strong>付款时间：</strong> @Model.PaymentTime
                        </div>
                        <div class="col-sm-6">
                            <strong>成交时间：</strong> @Model.CompleteTime
                        </div>
                    </div>
                    <table class="table table-bordered" style="margin-top:20px;">
                        <tr>
                            <th>商品名称</th>
                            <th>尺寸</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>优惠</th>
                            <th>运费</th>
                        </tr>
                        <tr>
                            <td>@Model.CommandityName</td>
                            <td>@Model.Size</td>
                            <td>@Model.CommandityPrice 元</td>
                            <td>1 件</td>
                            <td></td>
                            <td>卖家承担运费</td>
                        </tr>
                    </table>
                    <strong>实际成交价：</strong> @Model.Price 元
                    <hr />
                    @if (Model.State == 1)
                    {
                        <button class="btn btn-success" onclick="pay()">立即支付</button>
                        <button class="btn btn-default" onclick="cancel()">取消订单</button>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@section script{
    <script>
        function pay() {
            if (confirm("确认付款 @Model.Price 元吗？")) {
                $.ajax({
                    type: "Post",
                    url: "/Home/Pay",
                    data: { id: "@Model.Id" },
                    success: function (data) {
                        alert("支付成功！");
                        location.href = "/Home/Settlement?id=@Model.Id";
                    },
                })
            }
        }
        function complete() {
            if (confirm("确认收货吗？")) {
                $.ajax({
                    type: "Post",
                    url: "/Home/Complete",
                    data: { id: "@Model.Id" },
                    success: function (data) {
                        alert("订单已完成！");
                        location.href = "/Home/Settlement?id=@Model.Id";
                    },
                })
            }
        }
        function cancel() {
            if (confirm("确认取消订单吗？")) {
                $.ajax({
                    type: "Post",
                    url: "/Home/Cancel",
                    data: { id: "@Model.Id" },
                    success: function (data) {
                        alert("订单已取消！");
                        location.href = "/Home/Settlement?id=@Model.Id";
                    },
                })
            }
        }
    </script>    
}
